<template>
	<view class="page-index">
		<view class="name">房屋信息</view>
		<view class="types">
			<view class="types-item1">发布类型</view>
			<view class="types-item2">
				<view :class="[typeIndex == index ? 'marlef change' : 'marlef nochange']" v-for="(item, index) in typeArr" :key="index" @click="typeIndexChange(index)">{{ item.name }}</view>
			</view>
		</view>
		<view class="title" :class="iserr1 ? 'spaceErr' : ''" @click="iserr1 = false">
			<view class="title-item1">标题</view>
			<view class="title-item2"><input type="text" placeholder="请输入标题" class="input" v-model="form.title" /></view>
		</view>
		<!-- 房源位置 -->
		<view class="position" :class="iserr2 ? 'spaceErr' : ''" @click="iserr2 = false">
			<view class="position-item1">房源位置</view>
			<view class="position-item2">
				<view class="chage">
					<picker @change="bindPickerChange" :value="positionIndex" :range="selectList.areas" range-key="title">
						<view class="uni-input" v-if="selectList.areas[positionIndex] || formData.areasTitle">
							<text v-if="selectList.areas[positionIndex]">{{ selectList.areas[positionIndex].title }}</text>
							<text v-else>{{ formData.areasTitle }}</text>
						</view>
						<view class="uni-input" v-else>
							<text style="opacity: 0.5;">请选择房源位置</text>
							<image src="/static/user/right.png" mode="" style="width: 40rpx;height: 40rpx;line-height: 112rpx;"></image>
						</view>
					</picker>
				</view>
				<view class="position-items">
					<text v-if="form.address">{{ form.address }}</text>
					<text v-else>请选择位置</text>
				</view>
			</view>
		</view>
		<!-- 卧室面积 -->
		<view class="title" :class="iserr3 ? 'spaceErr' : ''" @click="iserr3 = false">
			<view class="title-item1">面积</view>
			<view class="title-item2"><input type="number" placeholder="请填写面积" class="input" v-model="form.acreage" /></view>
		</view>
		<!-- 户型/朝向 -->
		<!-- 		<view class="position">
			<view class="position-item1">
				户型/朝向
			</view>
			<view class="position-item2">
				<view class="chage">
					<picker @change="housePickerChange" :value="houseIndex" :range="selectList.house" range-key='title'>
						<view class="uni-input" v-if="selectList.house[houseIndex]||formData.houseTitle">
							<text v-if="selectList.house[houseIndex]">{{selectList.house[houseIndex].title}}</text><text v-else>{{formData.houseTitle}}</text>
						</view>
						<view class="uni-input" v-else style="opacity: 0.5;">请选择户型/朝向</view>
					</picker>
				</view>
			</view>
			<image src="/static/user/right.png" mode="" style="width: 40rpx;height: 40rpx;line-height: 112rpx;"></image>
		</view> -->
		<!-- 楼层|总楼层 -->
		<view class="position" :class="iserr4 ? 'spaceErr' : ''" @click="iserr4 = false">
			<view class="position-item1">楼层|总楼层</view>
			<view class="position-item2">
				<view class="chage">
					<picker @change="floorPickerChange" :value="floorIndex" :range="floorArr" mode="multiSelector" range-key="title" @columnchange="MultiColumnChange">
						<view class="uni-input" v-if="form.total_floor" s>
							<text>{{ form.floor }}|{{ form.total_floor }}层</text>
							<image src="/static/user/right.png" mode="" style="width: 40rpx;height: 40rpx;line-height: 112rpx;"></image>
						</view>
						<view class="uni-input" v-else>
							<text style="opacity: 0.5;">请选择楼层</text>
							<image src="/static/user/right.png" mode="" style="width: 40rpx;height: 40rpx;line-height: 112rpx;"></image>
						</view>
					</picker>
				</view>
			</view>
		</view>
		<!-- 出租类型 -->
		<view class="position" :class="iserr5 ? 'spaceErr' : ''" @click="iserr5 = false" v-if="typeIndex == 0">
			<view class="position-item1">出租类型</view>
			<view class="position-item2">
				<view class="chage">
					<picker @change="tentype1PickerChange" :value="tentypeIndex1" :range="selectList.tentype1" range-key="title">
						<view class="uni-input" v-if="selectList.tentype1[tentypeIndex1] || formData.tentypeTitle">
							<text v-if="selectList.tentype1[tentypeIndex1].title">{{ selectList.tentype1[tentypeIndex1].title }}</text>
							<text v-else>{{ formData.tentypeTitle }}</text>
						</view>
						<view class="uni-input" v-else>
							<text style="opacity: 0.5;">请选择出租类型</text>
							<image src="/static/user/right.png" mode="" style="width: 40rpx;height: 40rpx;line-height: 112rpx;"></image>
						</view>
					</picker>
				</view>
			</view>
		</view>
		<!-- 房源类型 -->
		<view class="position" :class="iserr5 ? 'spaceErr' : ''" @click="iserr5 = false" v-if="typeIndex == 1">
			<view class="position-item1">房源类型</view>
			<view class="position-item2">
				<view class="chage">
					<picker @change="tentype2PickerChange" :value="tentypeIndex2" :range="selectList.tentype2" range-key="title">
						<view class="uni-input" v-if="selectList.tentype2[tentypeIndex2] || formData.tentypeTitle">
							<text v-if="selectList.tentype2[tentypeIndex2].title">{{ selectList.tentype2[tentypeIndex2].title }}</text>
							<text v-else>{{ formData.tentypeTitle }}</text>
						</view>
						<view class="uni-input" v-else>
							<text style="opacity: 0.5;">请选择房源类型</text>
							<image src="/static/user/right.png" mode="" style="width: 40rpx;height: 40rpx;line-height: 112rpx;"></image>
						</view>
					</picker>
				</view>
			</view>
		</view>
		<!-- 装修进度 -->
		<view class="position" :class="iserr6 ? 'spaceErr' : ''" @click="iserr6 = false">
			<view class="position-item1">装修类型</view>
			<view class="position-item2">
				<view class="chage">
					<picker @change="furnishPickerChange" :value="furnishIndex" :range="selectList.furnish" range-key="title">
						<view class="uni-input" v-if="selectList.furnish[furnishIndex] || formData.furnishTitle">
							<text v-if="selectList.furnish[furnishIndex].title">{{ selectList.furnish[furnishIndex].title }}</text>
							<text v-else>{{ formData.furnishTitle }}</text>
						</view>
						<view class="uni-input" v-else>
							<text style="opacity: 0.5;">请选择装修类型</text>
							<image src="/static/user/right.png" mode="" style="width: 40rpx;height: 40rpx;line-height: 112rpx;"></image>
						</view>
					</picker>
				</view>
			</view>
		</view>
		<!-- 房屋大小 -->
		<view class="position" :class="iserr7 ? 'spaceErr' : ''" @click="iserr7 = false">
			<view class="position-item1">户型</view>
			<view class="position-item2">
				<view class="chage">
					<picker @change="sizePickerChange" :value="sizeIndex" :range="selectList.size" range-key="title">
						<view class="uni-input" v-if="selectList.size[sizeIndex] || formData.sizeTitle">
							<text v-if="selectList.size[sizeIndex].title">{{ selectList.size[sizeIndex].title }}</text>
							<text v-else>{{ formData.sizeTitle }}</text>
						</view>
						<view class="uni-input" v-else>
							<text style="opacity: 0.5;">请选择户型</text>
							<image src="/static/user/right.png" mode="" style="width: 40rpx;height: 40rpx;line-height: 112rpx;"></image>
						</view>
					</picker>
				</view>
			</view>
		</view>
		<!-- 月租金 -->
		<view class="title" :class="iserr8 ? 'spaceErr' : ''" @click="iserr8 = false">
			<view class="title-item1">房屋价格</view>
			<view class="title-item2" style="display: flex;"><input type="number" placeholder="请输入房屋价格" class="input" v-model="form.rent" style="border: 2rpx solid rgba(0, 0, 0, 0.08);height: 68rpx;padding-left: 22rpx;" /></view>
			<view style="margin-left: 16rpx;">
				<!-- 				<view class="">
					{{tentypeIndex2}}
				</view> -->
				<text v-if="typeIndex == 0">元/月</text>
				<text v-if="typeIndex == 1 && tentypeIndex2 != 0">元/㎡</text>
				<text v-if="typeIndex == 1 && tentypeIndex2 == 0">万元</text>
			</view>
		</view>
		<!-- 支付方式 -->
		<view class="position" :class="iserr9 ? 'spaceErr' : ''" @click="iserr9 = false" v-if="typeIndex == 0">
			<view class="position-item1">支付方式</view>
			<view class="position-item2">
				<view class="chage">
					<picker @change="payPickerChange" :value="payIndex" :range="selectList.pay" range-key="title">
						<view class="uni-input" v-if="selectList.pay[payIndex] || formData.payTitle">
							<text v-if="selectList.pay[payIndex].title">{{ selectList.pay[payIndex].title }}</text>
							<text v-else>{{ formData.payTitle }}</text>
						</view>
						<view class="uni-input" v-else>
							<text style="opacity: 0.5;">请选择支付方式</text>
							<image src="/static/user/right.png" mode="" style="width: 40rpx;height: 40rpx;line-height: 112rpx;"></image>
						</view>
					</picker>
				</view>
			</view>
		</view>
		<!-- 手机号 -->
		<view class="title" :class="iserr10 ? 'spaceErr' : ''" @click="iserr10 = false">
			<view class="title-item1">联系电话</view>
			<view class="title-item2"><input type="number" placeholder="请输入手机号" class="input" v-model="form.phone" :maxlength="11" style="z-index: 0;" /></view>
		</view>
		<!-- 房屋信息 -->
		<view class="name">房屋图片(长按删除)</view>
		<view class="image-box">
			<view class="image-item" v-for="(item, index) in form.images" :key="index"><image :src="item" mode="" class="image" @longpress="deleteImage(item, index)"></image></view>
			<view class="dashed" v-if="form.images.length < 6" @click="myUpload">
				<view class="box" style="margin-top: 20rpx;">
					<image src="/static/user/photo.png" mode="" style="width: 48rpx;height: 48rpx;"></image>
					<view class="add">添加</view>
				</view>
				<!-- <cropper selWidth="750rpx" selHeight="550rpx" @upload="myUpload" avatarStyle="width:116px;height:116px;position: absolute;;top:0;left:0"></cropper> -->
			</view>
		</view>
		<view class="name" v-if="typeIndex == 0">房屋详情(按真实情况多选)</view>
		<view v-if="typeIndex == 0">
			<view class="configure-box" v-if="!more">
				<view :class="[form.configure_ids.indexOf(item.id) > -1 ? 'configure color' : 'configure']" v-for="(item, index) in selectList.configure ? selectList.configure.slice(0, 9) : selectList.configure" :key="index" @click="configuress(item)">{{ item.title }}</view>
				<view class="configure color" @click="this.more = true">更多</view>
			</view>
			<view class="configure-box" v-else>
				<view :class="[form.configure_ids.indexOf(item.id) > -1 ? 'configure color' : 'configure']" v-for="(item, index) in selectList.configure" :key="index" @click="configurePush(item)">{{ item.title }}</view>
			</view>
		</view>
		<view class="name">房屋描述</view>
		<view class="content" style="margin: 0 32rpx;">
			<textarea placeholder="请输入房屋描述" :maxlength="-1" v-model="form.content" :focus="focus" v-if="focus" @blur="focus = false"></textarea>
			<view v-model="form.content" @click="focus = true" v-if="!focus" style="width: 100%;height: 200rpx;">
				<text v-if="form.content != ''">{{ form.content }}</text>
				<text v-else style="color: #999999;">请输入房屋描述</text>
			</view>
		</view>

		<view class="" style="height: 300rpx;"></view>
		<view class="fixed">
			<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" class="nbtn" v-if="!token"><view style="text-align: center;color: #ffffff;">发布房源</view></button>
			<view class="Submit" @click="submit()" v-if="token">发布房源</view>
		</view>
	</view>
</template>

<script>
import cropper from '@/components/lxiaoxiao-cropper/lxiaoxiao-cropper.vue';
import * as index from '@/api/index.js';
import * as user from '@/api/user.js';
export default {
	components: {
		cropper
	},
	data() {
		return {
			imgurl: '',
			selectList: [], //选择列表
			formData: [],
			jieliu: true,
			realestateId: '', //房源id
			form: {
				title: '', //标题
				areas_id: '', //区域ID
				address: '', //位置信息
				address_name: '', //详细地址
				latitude: '', //纬度
				longitude: '', //经度
				acreage: '', //卧室面积
				tentype_id: '', //出租类型
				rent: '', //租金
				pay_id: '', //支付方式
				floor: '', //房屋楼层
				total_floor: '', //房屋总楼层
				images: [], //图片
				configure_ids: [], //房屋配置
				content: '', //房屋描述
				phone: '', //手机号
				furnish_id: '', //装修进度
				size_id: '' //房屋大小
			}, //数据
			positionIndex: -1, //区域
			houseIndex: -1, //卧室面积
			tentypeIndex1: -1, //出租类型
			tentypeIndex2: -1, //房源类型
			payIndex: -1, //支付方式
			furnishIndex: -1, //装修进度
			sizeIndex: -1, //房屋大小
			tentype_id1: '',
			tentype_id2: '',
			floorArr: [[], []],
			floorIndex: [0, 0],
			selectFloor: [],
			loginInfo: {
				code: '',
				phoneCode: ''
			}, //登录信息
			more: false,
			iserr1: false,
			iserr2: false,
			iserr3: false,
			iserr4: false,
			iserr5: false,
			iserr6: false,
			iserr7: false,
			iserr8: false,
			iserr9: false,
			iserr10: false,
			focus: false, //textarea焦点
			typeArr: [
				{
					name: '出租'
				},
				{
					name: '出售'
				}
			],
			typeIndex: 0,
			token: ''
		};
	},
	onLoad(params) {
		this.token = uni.getStorageSync('token');
		this.typeIndex = parseInt(params.type);
		this.getSelect();
		this.getFloor();
		this.realestateId = params.realestateId;
		if (this.realestateId) {
			this.getEditRealestateInfo();
		}
	},
	methods: {
		myUpload() {
			const that = this;
			// that.imgurl = rsp.path;
			// this.form.images.push(rsp.path)
			// uni.uploadFile({
			// 	url: 'https://shangban.wanhedashuju.com/api/common/upload', //仅为示例，非真实的接口地址
			// 	filePath: rsp.path,
			// 	header: {
			// 		token: uni.getStorageSync('token')
			// 	},
			// 	name: 'file',
			// 	success: (uploadFileRes) => {
			// 		var imgurl = JSON.parse(uploadFileRes.data).data.fullurl
			// 		var imgurls = imgurl.replace(/\"/g, "")
			// 		that.form.images.push(imgurls)

			// 	}
			// });
			uni.chooseMedia({
				count: 1,
				mediaType: ['image'],
				sourceType: ['album', 'camera'],
				maxDuration: 30,
				camera: 'back',
				success(res) {
					console.log(res, 'res');
					uni.uploadFile({
						url: 'https://shangban.wanhedashuju.com/api/common/upload', //仅为示例，非真实的接口地址
						filePath: res.tempFiles[0].tempFilePath,
						name: 'file',
						formData: {
							user: 'test',
							'Content-type': 'application/json',
							token: uni.getStorageSync('token')
						},
						success(uploadFileRes) {
							console.log(uploadFileRes, 'uploadFileRes');
							var imgurl = JSON.parse(uploadFileRes.data).data.fullurl;
							var imgurls = imgurl.replace(/\"/g, '');
							that.form.images.push(imgurls);
						}
					});
				}
			});

			//更新头像方式一
			// rsp.avatar.imgSrc = rsp.path; //更新头像方式二
		},
		// 编辑信息
		getEditRealestateInfo() {
			this.more = true;
			user.getEditRealestateInfo({ realestateId: this.realestateId }).then(res => {
				var configure_ids = [];
				this.form = res.data.form;
				this.formData = res.data.data;
				this.form.configure_ids.forEach(item => {
					configure_ids.push(parseInt(item));
				});
				this.form.configure_ids = configure_ids;
				this.tentype_id1 = res.data.form.tentype_id;
				this.tentype_id2 = res.data.form.tentype_id;
			});
		},
		getSelect() {
			index.getSelect().then(res => {
				this.selectList = res.data;
			});
		},
		getFloor() {
			user.selectFloor().then(res => {
				this.floorArr = [res.data, res.data[0].list];
			});
		},
		MultiColumnChange(e) {
			if (e.detail.column == 0) {
				this.floorArr = [this.floorArr[0], this.floorArr[0][e.detail.value].list];
				this.floorIndex = [e.detail.value, this.floorIndex[1]];
			} else if (e.detail.column == 1) {
				this.floorIndex = [this.floorIndex[0], e.detail.value];
			}
		},
		floorPickerChange(e) {
			this.form.floor = this.floorArr[0][e.detail.value[0]].value;
			this.form.total_floor = this.floorArr[1][e.detail.value[1]].value;
		},
		// 房源位置确认
		bindPickerChange(e) {
			let that = this;
			this.positionIndex = e.detail.value;
			this.form.areas_id = this.selectList.areas[this.positionIndex].id;
			uni.chooseLocation({
				success: function(res) {
					that.form.address = res.address;
					that.form.address_name = res.name;
					that.form.latitude = res.latitude;
					that.form.longitude = res.longitude;
				}
			});
		},
		// 户型/朝向
		// housePickerChange(e) {
		// 	let that = this
		// 	this.houseIndex = e.detail.value
		// 	this.form.house_id = this.selectList.house[this.houseIndex].id
		// },
		// 出租类型
		tentype1PickerChange(e) {
			let that = this;
			this.tentypeIndex1 = e.detail.value;
			this.tentype_id1 = this.selectList.tentype1[this.tentypeIndex1].id;
		},
		// 房源类型
		tentype2PickerChange(e) {
			let that = this;
			this.tentypeIndex2 = e.detail.value;
			this.tentype_id2 = this.selectList.tentype2[this.tentypeIndex2].id;
		},
		// 支付方式
		payPickerChange(e) {
			let that = this;
			this.payIndex = e.detail.value;
			this.form.pay_id = this.selectList.pay[this.payIndex].id;
		},
		// 装修进度
		furnishPickerChange(e) {
			let that = this;
			this.furnishIndex = e.detail.value;
			this.form.furnish_id = this.selectList.furnish[this.furnishIndex].id;
		},
		// 房屋大小
		sizePickerChange(e) {
			let that = this;
			this.sizeIndex = e.detail.value;
			this.form.size_id = this.selectList.size[this.sizeIndex].id;
		},
		configuress(item) {
			this.more = true;
			this.configurePush(item);
		},
		configurePush(item) {
			if (this.form.configure_ids.indexOf(item.id) < 0) {
				this.form.configure_ids.push(item.id);
			} else {
				this.removeByValue(this.form.configure_ids, item.id);
			}
		},
		removeByValue(arr, val) {
			for (var i = 0; i < arr.length; i++) {
				if (arr[i] == val) {
					arr.splice(i, 1);
					break;
				}
			}
		},
		// 发布房源
		submit() {
			if (!this.jieliu) {
				return;
			}
			this.jieliu = false;
			setTimeout(() => {
				this.jieliu = true;
			}, 2000);
			if (this.typeIndex == 0) {
				if (this.form.title == '') {
					this.iserr1 = true;
					this.errModel('请输入标题');
					return;
				} else if (this.form.address == '' || this.form.address_name == '') {
					this.iserr2 = true;
					this.errModel('请选择房源位置');
					return;
				} else if (this.form.acreage == '') {
					this.iserr3 = true;
					this.errModel('请填写面积');
					return;
				} else if (this.form.addfloorress == '' || this.form.total_floor == '') {
					this.iserr4 = true;
					this.errModel('请选择楼层');
					return;
				} else if (this.tentype_id1 == '') {
					this.iserr5 = true;
					this.errModel('请选择出租类型');
					return;
				} else if (this.form.furnish_id == '') {
					this.iserr6 = true;
					this.errModel('请选择装修类型');
					return;
				} else if (this.form.size_id == '') {
					this.iserr7 = true;
					this.errModel('请选择户型');
					return;
				} else if (this.form.rent == '') {
					this.iserr8 = true;
					this.errModel('请输入月租金');
					return;
				} else if (this.form.pay_id == '') {
					if (this.typeIndex == 0) {
						this.iserr9 = true;
						this.errModel('请选择支付方式');
						return;
					}
				} else if (this.form.phone == '') {
					this.iserr10 = true;
					this.errModel('请输入手机号');
					return;
				}
				var form = this.form;
				var objString = JSON.stringify(form);
				var obj2 = JSON.parse(objString);
				obj2.type = 1;
				obj2.tentype_id = this.tentype_id1;
				obj2.images = obj2.images.join();
				obj2.configure_ids = obj2.configure_ids.join();
				obj2.realestateId = this.realestateId;
				user.saveRealestate(obj2).then(res => {
					wx.showLoading({
						title: '正在发布',
						mask: 'true'
					});
					if (res.code == 1) {
						wx.hideLoading();
						uni.showToast({
							icon: 'none',
							title: '发布成功',
							duration: 2000
						});
						setTimeout(() => {
							uni.redirectTo({
								url: `/pages/user/myRelease/myRelease?type=${1}&index=${0}`
							});
						}, 1000);
					} else {
						wx.hideLoading();
					}
				});
			} else {
				if (this.form.title == '') {
					this.iserr1 = true;
					this.errModel('请输入标题');
					return;
				} else if (this.form.address == '' || this.form.address_name == '') {
					this.iserr2 = true;
					this.errModel('请选择房源位置');
					return;
				} else if (this.form.acreage == '') {
					this.iserr3 = true;
					this.errModel('请填写面积');
					return;
				} else if (this.form.addfloorress == '' || this.form.total_floor == '') {
					this.iserr4 = true;
					this.errModel('请选择楼层');
					return;
				} else if (this.tentype_id2 == '') {
					this.iserr5 = true;
					this.errModel('请选择房源类型');
					return;
				} else if (this.form.furnish_id == '') {
					this.iserr6 = true;
					this.errModel('请选择装修类型');
					return;
				} else if (this.form.size_id == '') {
					this.iserr7 = true;
					this.errModel('请选择户型');
					return;
				} else if (this.form.rent == '') {
					this.iserr8 = true;
					this.errModel('请输入房源单价');
					return;
				} else if (this.form.phone == '') {
					this.iserr10 = true;
					this.errModel('请输入手机号');
					return;
				}
				var form = this.form;
				var objString = JSON.stringify(form);
				var obj2 = JSON.parse(objString);
				obj2.type = 2;
				obj2.tentype_id = this.tentype_id2;
				obj2.images = obj2.images.join();
				obj2.configure_ids = '';
				obj2.realestateId = this.realestateId;
				user.saveRealestate(obj2).then(res => {
					wx.showLoading({
						title: '正在发布',
						mask: 'true'
					});
					if (res.code == 1) {
						wx.hideLoading();
						uni.showToast({
							icon: 'none',
							title: '发布成功',
							duration: 2000
						});
						setTimeout(() => {
							uni.redirectTo({
								url: `/pages/user/myRelease/myRelease?type=${2}&index=${1}`
							});
						}, 1000);
					} else {
						wx.hideLoading();
					}
				});
			}
			// if (this.form.title == '') {
			// 	this.iserr1 = true
			// 	this.errModel('请输入标题')
			// 	return
			// } else if (this.form.address == '' || this.form.address_name == '') {
			// 	this.iserr2 = true
			// 	this.errModel('请选择房源位置')
			// 	return
			// } else if (this.form.acreage == '') {
			// 	this.iserr3 = true
			// 	this.errModel('请填写面积')
			// 	return
			// } else if (this.form.addfloorress == '' || this.form.total_floor == '') {
			// 	this.iserr4 = true
			// 	this.errModel('请选择楼层')
			// 	return
			// } else if (this.form.tentype_id == '') {
			// 	this.iserr5 = true
			// 	this.errModel('请选择出租类型')
			// 	return
			// } else if (this.form.furnish_id == '') {
			// 	this.iserr6 = true
			// 	this.errModel('请选择装修类型')
			// 	return
			// } else if (this.form.size_id == '') {
			// 	this.iserr7 = true
			// 	this.errModel('请选择户型')
			// 	return
			// } else if (this.form.rent == '') {
			// 	this.iserr8 = true
			// 	this.errModel('请输入价格')
			// 	return
			// } else if (this.form.pay_id == '') {
			// 	if (this.typeIndex == 0) {
			// 		this.iserr9 = true
			// 		this.errModel('请选择支付方式')
			// 		return
			// 	}
			// } else if (this.form.phone == '') {
			// 	this.iserr10 = true
			// 	this.errModel('请输入手机号')
			// 	return
			// }
		},
		getPhoneNumber(e) {
			let that = this;
			that.loginInfo.phoneCode = e.detail.code;
			if (that.loginInfo.phoneCode) {
				uni.login({
					provider: 'weixin',
					onlyAuthorize: true,
					success: function(loginRes) {
						that.loginInfo.code = loginRes.code;
						that.wxLogin();
					}
				});
			}
		},
		wxLogin() {
			let that = this;
			user.wxLogin(this.loginInfo).then(res => {
				console.log(res);
				uni.setStorage({
					key: 'token',
					data: res.data.token,
					success: function() {
						that.token = res.data.token;
					}
				});
			});
		},
		deleteImage(item, index) {
			let that = this;
			uni.showModal({
				title: '提示',
				content: '是否删除该图片',
				success: function(res) {
					if (res.confirm) {
						that.form.images.splice(index, 1);
					} else if (res.cancel) {
						console.log(item, index);
					}
				}
			});
		},
		errModel(why) {
			uni.showToast({
				icon: 'none',
				title: why,
				duration: 2000
			});
		},
		typeIndexChange(index) {
			console.log(this.realestateId);
			if (this.realestateId) {
				uni.showToast({
					icon: 'none',
					title: '编辑信息不可切换类型',
					duration: 2000
				});
			} else {
				this.typeIndex = index;
			}
		}
	}
};
</script>

<style scoped lang="scss">
.page-index {
	font-family: PingFang SC-Medium, PingFang SC;
	padding: 0rpx;
	font-size: 28rpx;
	font-weight: 400;
	color: #202020;

	.uni-input {
		display: flex;
		justify-content: space-between;
	}

	.name {
		height: 96rpx;
		line-height: 96rpx;
		font-size: 32rpx;
		font-weight: 700;
		color: #202020;
		padding: 0 32rpx;
	}

	.title {
		display: flex;
		justify-content: flex-start;
		border-bottom: 1rpx solid rgba(32, 32, 32, 0.08);
		height: 112rpx;
		line-height: 112rpx;
		padding: 0 32rpx;

		.title-item1 {
			width: 160rpx;
			height: 112rpx;
		}

		.title-item2 {
			width: 420rpx;
			display: flex;
			align-items: center;

			.input {
				width: 100%;
				height: 112rpx;
				border-radius: 8rpx;
			}
		}
	}

	.types {
		display: flex;
		justify-content: flex-start;
		align-items: center;
		border-bottom: 1rpx solid rgba(32, 32, 32, 0.08);
		height: 112rpx;
		// line-height: 112rpx;
		padding: 0 32rpx;

		.types-item1 {
			width: 160rpx;
			// height: 112rpx;
		}

		.types-item2 {
			display: flex;
			justify-content: flex-start;
			align-items: center;

			.change {
				padding: 8rpx 12rpx;
				background: #006fd0;
				border-radius: 8rpx;
				opacity: 1;
				color: #ffffff;
				font-size: 28rpx;
			}

			.nochange {
				padding: 8rpx 12rpx;
				background: #ebebeb;
				border-radius: 8rpx;
				opacity: 1;
				font-size: 28rpx;
			}

			.marlef:nth-child(2) {
				margin-left: 20rpx !important;
			}
		}
	}

	.position {
		display: flex;
		justify-content: flex-start;
		border-bottom: 1rpx solid rgba(32, 32, 32, 0.08);
		height: 112rpx;
		align-items: center;
		padding: 0 32rpx;

		.position-item1 {
			width: 160rpx;
			height: 112rpx;
			line-height: 112rpx;
		}

		.position-item2 {
			width: 550rpx;

			.change {
			}

			.position-items {
				font-size: 20rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #202020;
				opacity: 0.5;
			}
		}
	}

	.image-box {
		display: flex;
		justify-content: flex-start;
		flex-wrap: wrap;
		padding: 0 32rpx;

		.image-item {
			margin-right: 24rpx;

			.image {
				width: 200rpx;
				height: 146rpx;
				border-radius: 24rpx;
			}
		}

		.dashed {
			// padding: 0 32rpx;
			position: relative;

			width: 200rpx;
			height: 146rpx;
			border-radius: 24rpx;
			border: 2rpx dashed #d9d9d9;

			.box {
				text-align: center;

				.add {
					font-size: 24rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #202020;
					opacity: 0.5;
				}
			}
		}
	}

	.configure-box {
		display: flex;
		align-items: center;
		justify-content: flex-start;
		flex-wrap: wrap;
		padding: 0 32rpx;

		.configure {
			width: 128rpx;
			text-align: center;
			background: #f6f6f6;
			padding: 12rpx 0rpx;
			border-radius: 27rpx;
			margin-top: 24rpx;
			margin-right: 12rpx;
		}

		.configure:nth-child(5n) {
			margin-right: 0;
		}

		.color {
			background: #006fd0;
			color: #ffffff;
		}
	}

	.content {
		// padding: 0 56rpx;
		position: relative;
		height: 208rpx;
		border-radius: 16rpx;
		opacity: 1;
		border: 2rpx solid rgba(0, 0, 0, 0.1);
		padding: 24rpx;

		.length {
			position: absolute;
			right: 16rpx;
			bottom: 16rpx;
		}
	}

	.fixed {
		padding: 0 32rpx;
		background: #ffffff;
		position: fixed;
		bottom: 0;
		padding-bottom: env(safe-area-inset-bottom);
		width: 100%;
		height: 160rpx;
		margin: 0 -30rpx;

		// padding: 40rpx;
		.Submit {
			// width: 100%;
			// height: 100%;
			height: 80rpx;
			line-height: 80rpx;
			margin: 40rpx;
			background: #006fd0;
			text-align: center;
			border-radius: 16rpx;
			color: #ffffff;
		}

		.nbtn {
			height: 80rpx;
			line-height: 80rpx;
			margin: 40rpx;
			border-radius: 16rpx;
			text-align: center;
			-webkit-tap-highlight-color: transparent;
			box-sizing: content-box;
			cursor: pointer;
			position: relative;
			text-align: left;
			text-decoration: none;
			background: #ffffff;
			background: #006fd0;
			padding: 0;
			font-size: 28rpx;
		}

		.nbtn::after {
			border: 0px solid rgba(0, 0, 0, 0);
			border-radius: 0px;
		}
	}

	.spaceErr {
		border-top: 2rpx solid red;
		border-bottom: 2rpx solid red;
		color: red;
	}
}
</style>
